import Vue from 'vue'
import Router from 'vue-router'

// 引入品牌管理组件
const Trademark = () => import('@/views/product/Trademark')
const  Sku = ()=> import('@/views/product/Sku')
const Spu = () => import('@/views/product/Spu')
const Attr = () => import('@/views/product/Attr')
const User = () => import('@/views/acl/user')
const Role = ()=> import('@/views/acl/role')
const Menu = ()=> import('@/views/acl/menu')

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import { addLocale } from 'core-js'


// 路由规则的配置
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
      },
      
    ]
  },

  {
    name:'Product',
    path: '/product',
    // 每一个一级路由都用了潘家成写好的 layout,我们写的内容都是里面的二级路由
    component: Layout,
    meta: { title: '商品管理', icon: 'dashboard' },
    children: [
      {
        name: 'Trademark',
        path: 'trademark',
        component: Trademark,
        meta: { title: '品牌管理', icon: 'dashboard' }
      },
      {
        name: 'Sku',
        path: 'sku',
        component: Sku,
        meta: { title: 'sku管理', icon: 'dashboard' }
      },
      {
        name: 'Spu',
        path: 'spu',
        component: Spu,
        meta: { title: 'spu管理', icon: 'dashboard' }
      },
      {
        name: 'Attr',
        path: 'attr',
        component: Attr,
        meta: { title: 'attr管理', icon: 'dashboard' }
      }
    ]
  },
  {
    name: 'acl',
    path: '/acl',
    component: Layout,
    meta: { title: '权限管理', icon: 'dashboard' },
    children: [
      {
        name: 'Menu',
        path: 'menu',
        component: Menu,
        meta: { title: '菜单管理', icon: 'dashboard' }
      },
      {
          name: 'user',
          path: 'user',
          component: User,
          meta:{title:'用户管理',icon:'dashboard'}
      },
      {
        name: 'Role',
        path: 'role',
        component: Role,
        meta:{title:'角色管理',icon:'dashboard'}
    }

      
    ]
    
    
  },

  
 

 
 

  
  

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

// 创建路由器的函数
const createRouter = () => new Router({
  // mode: 'history', // require service support、
  // 路由跳转之后，如果之前有滚动条，那么让页面滚动到最初的位置
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
// 重置路由器  说官方并没有这个 api
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
